package logic

import (
	"context"
	"doctor-medicine-system/model/model"
	"doctor-medicine-system/zhoukao3rpc/internal/svc"
	"doctor-medicine-system/zhoukao3rpc/zhoukao3rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewGoodAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodAddLogic {
	return &GoodAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *GoodAddLogic) GoodAdd(in *zhoukao3rpc.GoodAddRequest) (*zhoukao3rpc.GoodAddResponse, error) {
	// todo: add your logic here and delete this line

	var goods model.Good

	goods = model.Good{
		Name:     in.Name,
		Xg:       in.Xg,
		Title:    in.Title,
		Num:      int(in.Num),
		AddCount: in.AddCount,
	}

	if err := goods.GoodsAdd(model.DB); err != nil {
		return nil, err
	}

	return &zhoukao3rpc.GoodAddResponse{
		GoodId: int64(goods.ID),
	}, nil
}
